package logic

import (
	"context"
	"errors"
	"order_srv/models/mysql"

	"order_srv/internal/svc"
	"order_srv/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowLogic {
	return &ShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowLogic) Show(in *order.ShowRequest) (*order.ShowResponse, error) {
	// todo: add your logic here and delete this line

	var og mysql.Order_Goods
	err := og.Show(int(in.UserId))
	if err != nil {
		logx.Error("订单商品详情展示失败")
		return nil, errors.New("订单商品详情展示失败")
	}
	if og.UserId == 0 {
		return nil, errors.New("订单商品详情不存在")
	}
	return &order.ShowResponse{Id: int32(og.ID), UserId: int32(og.UserId), Name: og.Name}, nil
}
